package ar.uade.edu.fain.ad.client.swing.util;

import ar.uade.edu.fain.ad.client.delegate.DelegateFactory;
import ar.uade.edu.fain.ad.client.delegate.rmi.util.RMIDelegateFactory;

public class ViewUtils {

	private static ViewUtils instance;

	private DelegateFactory delegateFactory;

	private ViewUtils() {
		super();
		final RMIDelegateFactory rmiDelegateFactory = new RMIDelegateFactory();
		String host = System.getProperty("server.host");
		if (host == null || host.isEmpty()) {
			System.out.println(
					"No ha sido configurado el hostname del server, "
					+ "usando defaults.");
			host = "localhost";
		}
		final String port = System.getProperty("server.port");
		rmiDelegateFactory.setServerName(host);
		if (port != null && !port.trim().isEmpty()) {
			rmiDelegateFactory.setServerPort(Integer.valueOf(port));
		}
		this.delegateFactory = rmiDelegateFactory;
	}

	public DelegateFactory getDelegateFactory() {
		return delegateFactory;
	}

	public static ViewUtils get() {
		if (instance == null) {
			instance = new ViewUtils();
		}
		return instance;
	}

}
